FileRead function

Syntax
FileRead refNum, "all"
FileRead refNum, "line"
FileRead refNum, "until", character
FileRead refNum, "bytes", numberOfBytes

Description
Reads data from the current mark (position) in a file opened with FileOpen and returns the data read from the file. After reading data, the file’s mark is set to the byte following the last byte read.

FileRead can read data in four different modes. The first parameter is a string that indicates which mode to use.

all
Reads all data from the current mark to the end of the file. After reading, the mark is set to one byte past the end of the file.

line
Reads data from the current mark up to (and including) the next carriage return character. After reading, the mark is set to the beginning of the next line.

until
Reads data from the current mark up to (and including) the specified character. After reading, the mark is set to the byte following the last byte read.

bytes
Reads the specified number of bytes beginning at the current mark. After reading, the mark is set to the byte following the last byte read.

Examples
Variable theFile, theData, refNum
theFile = (FindFolder "desk") & "FileIO Demo"
File(theFile).Text = "First line" & Return & "Second line"

// Read the file until the first "r"
refNum = FileOpen theFile
theData = FileRead refNum, "until", "r"
FileClose refNum
Message theData

// Read the whole file
refNum = FileOpen theFile
theData = FileRead refNum, "all"
FileClose refNum
Message theData

// Read the whole file from the current mark (4)
refNum = FileOpen theFile
FileSetPos refNum, 4
theData = FileRead refNum, "all" 
FileClose refNum
Message theData

// Read a single line
refNum = FileOpen theFile
theData = FileRead refNum "line" 
Message theData

// Read 5 bytes. The file is still open, so the reading begins following the first line.
theData = FileRead refNum, "bytes", 5
FileClose refNum
Message theData

See Also
Using the FileIO extension (page 136)

Author Info
FileRead, part of FileIO Extension
Copyright © 1998 Life OnLine Software (lr). All rights reserved.